package com.dd.cloud.user.DTO.km;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.DomDriver;
import lombok.Data;

/**
 * 康美接口响应信息
 *
 * @author zk
 */
@Data
public class ResultResDTO {
    /**
     * 状态码
     */
    private String resultCode;

    /**
     * 状态字符串
     */
    private String state;

    /**
     * 结果描述
     */
    private String description;

    /**
     * 订单信息
     */
    private OrderInfo orderInfo;

    @Data
    public static class OrderInfo {
        /**
         * ID号
         */
        private String reg_num;
        /**
         * 是否保存订单成功
         */
        private String IsSuccess;

        /**
         * 信息描述
         */
        private String message;

        /**
         * 订单号
         */
        private String orderid;

        /**
         * 康美处方号
         */
        private String prescriptionIds;

        /**
         * 康美处方号+平台处方号
         */
        private String prescriptionInfo;
    }

    public static ResultResDTO toPojo(String xml) {
        //new DomDriver("UTF-8", new NoNameCoder()) 解决下划线节点字段变成双下划线问题 reg_num 会变成 reg__num
        XStream xStream = new XStream(new DomDriver("UTF-8", new NoNameCoder()));
        //忽略xml多余参数
        xStream.ignoreUnknownElements();
        xStream.alias("result", ResultResDTO.class);
        return (ResultResDTO) xStream.fromXML(xml);
    }
}
